<?php
require("dbFunctions.php");

/**
 * Given a QR Code, update equipment name, serial number, condition
 * and set is_active to true for good measure.
 *
 * Author: Steve Gennaoui
 * Date: 11/21/2012
 */

$qr_code = $_REQUEST['qr_code'];
$equipment_name = $_REQUEST['type'];
$serial_number = $_REQUEST['serial_number'];
$condition = $_REQUEST['condition'];

if( !is_numeric($qr_code) )
	die("QR Code was non-numeric.");
if( is_null($equipment_name) )
	die("No equipment name provided.");
if( is_null($serial_number) )
	die("No serial number provided.");
if( is_null($condition) )
	die("No condition provided.");
if( !idIsValid($qr_code,"Equipment") )
	die("Equipment QR Code was invalid.");

$dbh = connectDB();

$query = "UPDATE Equipment SET equipment_name=:equip,serial_number=:sn,current_condition=:cond WHERE qr_code=:qr";
$stmt = $dbh->prepare($query);
$stmt->bindParam(':equip',$equipment_name);
$stmt->bindParam(':sn',$serial_number);
$stmt->bindParam(':cond',$condition);
$stmt->bindParam(':qr',$qr_code);
$stmt->execute();

$query = "UPDATE QR_Code SET is_active=1 WHERE qr_code=:qr";
$stmt = $dbh->prepare($query);
$stmt->bindParam(':qr',$qr_code);
$stmt->execute();

?>
